package com.yanqu.road.server.cmd.banquet.party;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.banquet.BanquetProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.banquet.BanquetModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.Protocol;

//@Cmd(code = GameProtocol.S_PARTY_OPEN, desc = "")
@Cmd(code = Protocol.S_BANQUET_CROSS_SETTING_UPDATE, desc = "更新宴会设置数据跨服返回")
public class CrossUpdateBanquetSettingCmd extends AbstractCommand {
    private int type;
    private String giftTypeAccept;
    private String banquetId;

    private String message;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        BanquetProto.UpdateBanquetSettingCrossRespMsg reqMsg = BanquetProto.UpdateBanquetSettingCrossRespMsg.parseFrom(packet.getBytes());
        this.type = reqMsg.getType();
        this.giftTypeAccept = reqMsg.getGiftTypeAccept();
        if (null == this.giftTypeAccept) {
            this.giftTypeAccept = "";
        }
        this.message = reqMsg.getMessage();
        this.banquetId = reqMsg.getBanquetId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        BanquetModule banquetModule = player.getModule(BanquetModule.class);

        banquetModule.updateUserBanquetSetting(this.type, this.giftTypeAccept, this.banquetId);

        BanquetProto.GetBanquetSettingRespMsg.Builder respMsg = BanquetProto.GetBanquetSettingRespMsg.newBuilder();
        respMsg.setType(type);
        respMsg.setGiftTypeAccept(this.giftTypeAccept);
        respMsg.setMessage(this.message);
        player.sendPacket(ClientProtocol.U_BANQUET_USER_SETTING_UPDATE, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
